package com.workoutgrabber.ui.model;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.workoutgrabber.model.ExerciseSet;

public class SetTableModel extends AbstractTableModel {
	private static String[] COLUMN_NAMES = {"Reps", "Weight"};
	
	private List<ExerciseSet> sets;
	
	public SetTableModel(){
		this.sets = new LinkedList<ExerciseSet>();
	}
	
	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public int getRowCount() {
		return sets.size();
	}
	
	@Override
	public String getColumnName(int column) {
		return COLUMN_NAMES[column];
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ExerciseSet set = sets.get(rowIndex);
		String cellText = "";
		
		switch (columnIndex) {
			case 0: cellText = set.getReps().toString();  break;
			case 1: cellText = set.getWeight().toString();  break;
		}
		
		return cellText;
	}

	public void add(ExerciseSet set) {
		sets.add(set);
		fireTableDataChanged();
	}

	public List<ExerciseSet> getSets() {
		return Collections.unmodifiableList(sets);
	}
}
